<?php
require 'inc_security.php';
$record_id = getValue('record_id');
$myform = new generate_form();
$myform->add('sli_title','sli_title',0,0,'Tiêu đề');
$myform->add('sli_content','sli_content',0,0,'Nội dung');
$myform->add('sli_link','sli_link',0,0,'#');
$myform->add('sli_active','sli_active',1,0,0);
$myform->add('sli_position','sli_position',1,0,0);
$myform->addTable($bg_table);
$myform->removeHTML(0);
$action = getValue('action','str','POST','');
if($action == 'execute'){
    $bg_errorMsg .= $myform->checkdata();
    $upload = new upload('sli_picture',$bg_filepath,$bg_extension,$limit_size);
    $filename = $upload->file_name;
    if($filename){
        $myform->add('sli_picture','filename',0,1,'');
		delete_file($bg_table,$id_field,$record_id,"sli_picture",$bg_filepath);
    }
    $upload1 = new upload('sli_picture_bg',$bg_filepath,$bg_extension,$limit_size);
    $filename1 = $upload1->file_name;
    if($filename1){
        $myform->add('sli_picture_bg','filename1',0,1,'');
		delete_file($bg_table,$id_field,$record_id,"sli_picture_bg",$bg_filepath);
    }
    $upload2 = new upload('sli_picture_title',$bg_filepath,$bg_extension,$limit_size);
    $filename2 = $upload2->file_name;
    if($filename2){
        $myform->add('sli_picture_title','filename2',0,1,'');
		delete_file($bg_table,$id_field,$record_id,"sli_picture_title",$bg_filepath);
    }
    $bg_errorMsg .= $upload->show_warning_error();
    if($bg_errorMsg == ''){
        $db_insert = new db_execute($myform->generate_update_SQL($id_field,$record_id));
        redirect('listing.php');
    }
}
//lấy dữ liệu record cần sửa đổi
$db_data 	= new db_query("SELECT * FROM " . $bg_table . " WHERE " . $id_field . " = " . $record_id);
if($row 		= mysql_fetch_assoc($db_data->result)){
	foreach($row as $key=>$value){
		$$key = $value;
	}
}else{
		exit();
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="vi" lang="vi" xmlns:og="http://ogp.me/ns#" xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <?=$load_header?>
</head>
<body>
<div class="module_header bold fix"><?=$module_name?></div>
<div id="wrapper">
    <?print_error_msg($bg_errorMsg)?>
    <?php $form = new form();
    ?>
    <?=$form->form_open()?>
    <?=$form->textnote('Các trường có dấu (<span class="form-asterick">*</span>) là bắt buộc nhập')?>
    <?=$form->text(array('label'=>'Tiêu đề - mô tả','name'=>'sli_title','id'=>'sli_title','value'=>getValue('sli_title','str','POST',$sli_title), 'placeholder'=> 'Tiêu đề không dài quá 255 ký tự'),0,'span6')?>
    <?=$form->textarea(array('label'=> 'Nội dung', 'name'=> 'sli_content', 'id'=> 'sli_content','value'=>getValue('sli_content','str','POST',$sli_content), 'style'=>'width:500px;height:100px', 'require'=> 0,'helptext'=>'Mỗi hàng cách nhau bằng dấu |'))?>
    <?=$form->text(array('label'=>'Link - đường dẫn','name'=>'sli_link','id'=>'sli_link','value'=>getValue('sli_link','str','POST',$sli_link), 'placeholder'=> 'Link của slide'),0,'span6')?>
    <?=$form->text(array('label'=>'Thứ tự','name'=>'sli_position','id'=>'sli_position','value'=>getValue('sli_position','int','POST',$sli_position)))?>
    <?=$form->checkbox(array('label'=> 'Xuất bản', 'name'=> 'sli_active', 'id'=> 'sli_active', 'value'=>1 ,'currentValue'=>getValue('sli_active','int','POST',$sli_active), 'helptext'=> 'Xuất bản ra trang (active)'))?>
    <div class="control-group">
        <label class="control-label">Ảnh slide</label>
        <div class="controls" style="width: 160px;height:90px;overflow:hidden">
            <img src="<?=$bg_filepath . getValue('sli_picture','str','POST',$sli_picture)?>" alt="Khong co anh"/>
        </div>
    </div>
    <?=$form->getFile(array('label'=>'Ảnh slide','title'=>'Ảnh slide','name'=>'sli_picture','id'=>'sli_picture','helptext'=>'Cỡ 491 x 375'))?>
   <div class="control-group">
        <label class="control-label">Ảnh nền slide</label>
        <div class="controls" style="width: 160px;height:90px;overflow:hidden">
            <img src="<?=$bg_filepath . getValue('sli_picture_bg','str','POST',$sli_picture_bg)?>" alt="Khong co anh"/>
        </div>
    </div>
   <?=$form->getFile(array('label'=>'Ảnh nền slide','title'=>'Ảnh nền slide','name'=>'sli_picture_bg','id'=>'sli_picture_bg','helptext'=>'Cỡ 1920 x 500'))?>
   <div class="control-group">
        <label class="control-label">Ảnh tiêu đề slide</label>
        <div class="controls" style="width: 160px;height:90px;overflow:hidden">
            <img src="<?=$bg_filepath . getValue('sli_picture_title','str','POST',$sli_picture_title)?>" alt="Khong co anh"/>
        </div>
    </div>
   <?=$form->getFile(array('label'=>'Ảnh tiêu đề slide','title'=>'Ảnh tiêu đề slide','name'=>'sli_picture_title','id'=>'sli_picture_title','helptext'=>'Cỡ 332 x 82'))?>
	<?=$form->form_action(array('label'=>array('Cập nhật','Nhập lại'),'type'=>array('submit','reset')))?>
	<?=$form->form_close()?>
</div>
</body>
</html>